<?php

$longopts = [
    'a:',         // --a=value
    'c:',        // --c=value
    'sDate::',   // --sDate[=value]  （:: 表示可选值）
    'eDate::',   // --eDate[=value]
    'p:',        // --p=value
    's:',         // --s=value
    'logCenter:',         // --s=value
    'h:',
    'd:'
];
$options = getopt('',$longopts);
$command = $options['c'] ?? null;
$port = $options['d'] ?? 9501;
$host = $options['h'] ?? '127.0.0.1';
$sDate    = $options['sDate'] ?? date('Y-m-d');
$eDate    = $options['eDate'] ?? date('Y-m-d');
$logCenter    = $options['logCenter'] ?? false;
$date    = $options['d'] ?? date('Y-m-d');
$data    = $options['a'] ?? ("hello world\n");
$platform    = $options['p'] ?? '';
$plat_server    = $options['s'] ?? '';

$client = new Swoole\Client(SWOOLE_SOCK_TCP);
if (!$client->connect($host, $port, -1)) {
    exit("connect failed. Error: {$client->errCode}\n");
}
if($command){
    $data = json_encode(compact('command','date','data','platform','plat_server','sDate','eDate','logCenter'));
}
$client->send($data);
echo $client->recv();
$client->close();
